package com.lemner.ke.activity;

import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.lemner.ke.R;
import com.lemner.ke.base.BaseActivity;
import com.lemner.ke.base.BaseListener;
import com.lemner.ke.bean.SuccessBean;
import com.lemner.ke.model.persional.ChangePwdModel;
import com.lemner.ke.util.SpUtils;

/**

* 作者：张恺

* 时间：2018/10/16

* 类描述：修改密码页面

*/

public class ChangePasswordActivity extends BaseActivity {
    private EditText et_old_pwd,et_new_pwd1,et_new_pwd2;
    private Button btn_finsh;
    private String userIds, mobile;

    @Override
    public int getLayoutFile() {
        return R.layout.activity_change_password;
    }

    @Override
    public void initView() {
        et_old_pwd=findViewById(R.id.et_old_password);
        et_new_pwd1=findViewById(R.id.et_new_password);
        et_new_pwd2=findViewById(R.id.et_new_password2);
        btn_finsh=findViewById(R.id.btn_finish);
    }

    @Override
    public void initEvent() {
        btn_finsh.setOnClickListener(this);
    }

    @Override
    public void initData() {
        userIds = SpUtils.getString(this, SpUtils.USERIDS);
        mobile = SpUtils.getString(this, SpUtils.MOBILE_PHOE);
    }

    @Override
    protected void initSetting() {
        topBar.setTitle("修改密码");
    }

    @Override
    public void onClick(View v) {
        String oldPsw = et_old_pwd.getText().toString();
        String newPsw1 = et_new_pwd1.getText().toString();
        String newPsw2 = et_new_pwd2.getText().toString();
        switch (v.getId()){
            case R.id.btn_finish:
                if (oldPsw.isEmpty()) {
                    showToast("请输入旧密码！");
                } else if (newPsw1.isEmpty()) {
                    showToast("请输入新密码！");
                } else if (newPsw2.isEmpty()) {
                    showToast("请输入确认密码！");
                } else if (oldPsw.length() < 6) {
                    showToast("旧密码应该大于6位！");
                } else if (newPsw1.length() < 6) {
                    showToast("新密码应该大于6位！");
                } else if (newPsw2.length() < 6) {
                    showToast("确认密码应该大于6位！");
                } else if (!newPsw1.equals(newPsw2)) {
                    showToast("两次密码输入不一致！");
                } else {
                    new ChangePwdModel().changePwd(userIds, mobile, oldPsw, newPsw1, new BaseListener<SuccessBean>() {
                        @Override
                        public void onResponse(SuccessBean successBean) {
                            showToast(successBean.getMsg());
                            finish();
                        }

                        @Override
                        public void onFail(String msg) {

                        }
                    });
                }
                break;
        }
    }
}
